package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;
import org.omg.CORBA.ARG_OUT;

import java.awt.*;

/**
 * ·@author：冯。
 * ·@version：v.1.0。
 * ·@docroot：表示产生文档的根路径。
 * ·@param：方法的参数类型。
 * ·@return：方法的返回类型。
 */
public class Power extends AbstractMapleStoryObject {
    public static Image[] imgs = new Image[10];
    static {
        for (int i = 0; i < 10; i++) {
            imgs[i] = ImageUtil.getImage("power" + i);
        }
    }
    public int value;
    public Power(){}

    public Power(MapleStoryClient msc,int x,int y){
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.speed = 5;
        this.live = true;
        this.value = msc.hero.hitValue;
    }
    public Power(MapleStoryClient msc,int x,int y,int HP){
        this(msc,x,y);
        this.value = HP;
    }

    @Override
    public void draw(Graphics g) {
        if (!live){
            msc.powers.remove(this);
            return;
        }
        drawValue(g);
        //g.drawString(value +"", x,y);
        move();
    }

    /**
     * 使用图片画伤害值
     * @param g 画笔
     */
    private void drawValue(Graphics g) {
        int power = this.value;
        if (power >= 9000){
            power = 9999;
        }
        int units = power % 10;
        power = power / 10;
        int tens = power % 10;
        power = power / 10;
        int hundreds = power % 10;
        power = power / 10;
        int thousands = power;
        if (tens == 0 && hundreds == 0 && thousands == 0 && units != 0){
            //只画个位
            g.drawImage(imgs[units],x,y,null);
        }
        if (hundreds == 0 && thousands == 0 && tens != 0){
            //画十位
            g.drawImage(imgs[tens],x,y,null);
            //画个位
            g.drawImage(imgs[units],x+30,y,null);
        }
        if (thousands == 0 && hundreds != 0){
            //画百位
            g.drawImage(imgs[hundreds],x,y,null);
            //画十位
            g.drawImage(imgs[tens],x+30,y,null);
            //画个位
            g.drawImage(imgs[units],x+60,y,null);
        }
        if (thousands != 0){
            //画千位
            g.drawImage(imgs[thousands],x,y,null);
            //画百位
            g.drawImage(imgs[hundreds],x+30,y,null);
            //画十位
            g.drawImage(imgs[tens],x+60,y,null);
            //画个位
            g.drawImage(imgs[units],x+90,y,null);
        }
    }
    private int moveCount;
    @Override
    public void move() {
        /*if (this.y <= 300){
            this.live = false;
        }
        this.y -= speed;*/
        moveCount++;
        if (moveCount % 20 ==0){
            this.live = false;
        }
        this.y -= speed;

        //所有mob的值都回循环
        /*for (int i = 0; i < msc.mobs.size(); i++) {
            Mob mob = msc.mobs.get(i);
            if (this.y <= mob.y - 100){
                this.live = false;
            }
            this.y -= speed;
            System.out.println(mob.y);
        }*/
    }
}
